#NAME:rmfnc
# rmfnc key
# rmfnc 'name
# rmfnc =scrname
# rmfnc ~scrname

unless(%ufncs&&$#_>0&&defined($_[1])){
    &mess("rmfnc: nothing to do\n","WARN");
    return;
}

my $del=sub{
    my $k=$_[0];
    my $pf=$ufncs{$k}->[0];
    &mess("rmfnc: ".&dec_kb($k).": ".$$pf.": ".$ufncs{$k}->[1]."\n");
    undef $ufncs{$k}->[0];
    undef $ufncs{$k}->[1];
    delete $ufncs{$k};
    if(substr($k,0,1)eq"_"){
	my $vn="p".substr($k,1);
	my $vnd=$vn."_def";
	{
	    no strict "refs";
	    undef ${$vn};
	    ${$vn}=${$vnd} if defined ${$vnd};
	}
    }
};

foreach(split(/\s/,$_[1])){
    my $k;
    my $s=substr($_,0,1);
    if(($s eq "="||$s eq "~")&&length($_)>1){
	my $sf=substr($_,1);
	my $n=0;
	foreach(keys(%ufncs)){
	    my $pf=$ufncs{$_}->[0];
	    if(($s eq "=" && $$pf eq $sf)
	       ||($s eq "~" && $$pf =~ $sf)){
		$del->($_);
		$n++;
	    }
	}
	unless($n){
	    &mess("no such script loaded: $sf\n","ERR");
	    return;
	}
	next;
    }elsif($s eq "'" && length($_)>1){
	$k=substr($_,1);
    }elsif($s eq "_" && length($_)>1){
	$k=$_;
    }else{
	$k=&enc_kb($_);
    }
    if(defined($k)&&exists($ufncs{$k})){
	$del->($k);
    }else{
	&mess("no such function assigned: $_\n","ERR");
	return;
    }
}

1;
